package com.example.qxfw.nyqx.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.ny.*;
import com.example.qxfw.common.entity.qx.*;
import com.example.qxfw.common.entity.ny.StationInfo;
import com.example.qxfw.common.entity.zy.AgriProduct;
import com.example.qxfw.nyqx.service.*;
import com.example.qxfw.nyqx.vo.CropYieldFcstListVo;
import com.example.qxfw.nyqx.vo.CropYieldHistoryListVo;
import com.example.qxfw.nyqx.vo.GrowdateFcstListVo;
import com.example.qxfw.qxzs.service.SpecialSrvStationService;
import com.example.qxfw.rcyw.service.SmallScaleStationService;
import com.example.qxfw.rcyw.service.StationInfoService;
import com.example.qxfw.ybzz.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@ApiIgnore
@Slf4j
@Api(tags = "农业气象-农气预报")
@RestController
@CrossOrigin
@RequestMapping("/AgriculturalForecastingController")
public class AgriculturalForecastingController {

    @Autowired
    private StationInfoService stationInfoService;

    @Autowired
    private TownshipForecastService townshipForecastService;

    @Autowired
    private SmallScaleStationService smallScaleStationService;

    @Autowired
    private CropGrowdateIndexlibService growdateIndexlibService;

    @Autowired
    private CropyieldFcstService cropyieldFcstService;
    @Autowired
    private CropyieldHistoryService cropyieldHistoryService;

    @Autowired
    private MsgMediumSmallScaleService msgMediumSmallScaleService;

    @Autowired
    private AgriWeatherDistRecordService agriWeatherDistRecordService;

    @Autowired
    private CropGrowdateFcstService cropGrowdateFcstService;

    @Autowired
    private SrvProductTemplateService srvProductTemplateService;

    @Autowired
    private AgriProductService agriProductService;

    @Autowired
    private ForecastInfoService forecastInfoService;

    @Autowired
    private SpecialSrvStationService specialSrvStationService;

    @Autowired
    private SysConfigService sysConfigService;

    @Autowired
    private CropWeatherDistIndexlibService cropWeatherDistIndexlibService;

    @Autowired
    private ThirtyYearDayStaticsService thirtyYearDayStaticsService;

    @Autowired
    private DiseaseindexlibService diseaseindexlibService;

    @Autowired
    private BadConditionService badConditionService;

    @Autowired
    private TownshipStationService townshipStationService;

    @ApiOperation("获取农服站信息")
    @GetMapping("/getStaitonInfoByMainCrop")
    public SysResult getStationInfo(String mainCrop) {
        List<StationInfo> list = stationInfoService.listByMainCrop(mainCrop);
        return SysResult.success(list);
    }

    @ApiOperation("使用参数查询农服站信息")
    @GetMapping("/getStationInfoByParam")
    public SysResult getStationInfo3(String stationId, String stationName, String mainCrop) {
        List<StationInfo> list4 = stationInfoService.listByParam(stationId, stationName, mainCrop);
        return SysResult.success(list4);
    }

    @ApiOperation("使用站点Id获取信息")
    @GetMapping("/getStationName")
    public SysResult getStationName(String stationId) {
        List<String> stationName = stationInfoService.listNameById(stationId);
        return SysResult.success(stationName);
    }

    @ApiOperation("使用站点名称获取信息")
    @GetMapping("/getStationId")
    public SysResult getStationId(String stationName) {
        List<String> stationId = stationInfoService.listIdByName(stationName);
        return SysResult.success(stationId);
    }

    @ApiOperation("获取乡镇预报")
    @GetMapping("/getTownShipForecastMaxTime")
    public SysResult getTownShipForecastMaxTime() {
        List<TownshipForecast> maxTime = townshipForecastService.getMaxTime();
        return SysResult.success(maxTime);
    }

    @ApiOperation("获取乡镇预报温度信息")
    @GetMapping("/getTownShipForecast")
    public SysResult getTownShipForecast(String dateChar, String nTimes, String stationId, String maxTemp, String minTemp) {
        String colum = "(case when maxtemp=-65535 then 0 else maxtemp end %2b case when mintemp=-65535 then 0 else mintemp end) / 2";
        List<TownshipForecast> list = townshipForecastService.listByParam1(dateChar, nTimes, stationId, colum, maxTemp, minTemp);
        return SysResult.success(list);
    }

    @ApiOperation("获取乡镇预报湿度信息")
    @GetMapping("/getTownShipForecast1")
    public SysResult getTownShipForecast1(String dateChar, String nTimes, String stationId, String maxTemp, String minTemp) {
        String colum = "avg(case when humid=-65535 then 0 else humid end) as humid";
        List<TownshipForecast> list = townshipForecastService.listByParam2(dateChar, nTimes, stationId, colum, maxTemp, minTemp);
        return SysResult.success(list);
    }

    @GetMapping("/getTownShipForecast2")
    public SysResult getTownShipForecast2(String dateChar, String stationId, String minTemp, String maxTemp) {
        List<TownshipForecast> list = townshipForecastService.getList3(dateChar, stationId, minTemp, maxTemp);
        return SysResult.success(list);
    }

    @GetMapping("/getTownShipForecast3")
    public SysResult getTownShipForecast3(String dateChar, String stationId, String minTemp) {
        List<TownshipForecast> list = townshipForecastService.getList4(dateChar, stationId, minTemp);
        return SysResult.success(list);
    }

    @GetMapping("/getTownShipForecast4")
    public SysResult getTownShipForecast4(String dateChar, String stationId, String maxTemp) {
        List<TownshipForecast> list = townshipForecastService.getList5(dateChar, stationId, maxTemp);
        return SysResult.success(list);
    }

    @GetMapping("/getTownShipForecast5")
    public SysResult getTownShipForecast5(String dateChar, String stationId, String minTemp, String maxTemp) {
        List<TownshipForecast> list = townshipForecastService.getList6(dateChar, stationId, minTemp, maxTemp);
        return SysResult.success(list);
    }

    @GetMapping("/getSmallScaleStationId")
    public SysResult getSmallScaleStationId(String stationName) {
        List<String> stationId = smallScaleStationService.getStationId(stationName);
        return SysResult.success(stationId);
    }

    @ApiOperation("获取作物名称-作物发育期指标库")
    @GetMapping("/getGrowCropName")
    public SysResult getGrowCropName() {
        List<String> cropName = growdateIndexlibService.getCropName();
        return SysResult.success(cropName);
    }

    @GetMapping("/getGrowCropName1")
    public SysResult getGrowCropName1(String indexId) {
        List<String> cropName = growdateIndexlibService.getCropName1(indexId);
        return SysResult.success(cropName);
    }

    @ApiOperation("获取作物品种-作物发育期指标库")
    @GetMapping("/getGrowType")
    public SysResult getGrowType(String cropName) {
        List<String> type = growdateIndexlibService.getType(cropName);
        return SysResult.success(type);
    }

    @GetMapping("/getGrowType1")
    public SysResult getGrowType1() {
        List<String> type1 = growdateIndexlibService.getType1();
        return SysResult.success(type1);
    }

    @ApiOperation("获取发育期名称")
    @GetMapping("/getGrowdateName")
    public SysResult getGrowdateName(String cropName) {
        List<String> growDateName = growdateIndexlibService.getGrowDateName(cropName);
        return SysResult.success(growDateName);
    }

    @GetMapping("/getGrowDateIndexlib")
    public SysResult getGrowDateIndexlib(String cropName) {
        List<CropGrowdateIndexlib> list = growdateIndexlibService.getList(cropName);
        return SysResult.success(list);
    }

    @GetMapping("/getGrowDateIndexlib1")
    public SysResult getGrowDateIndexlib1(String time1, String time2) {
        List<CropGrowdateIndexlib> list = growdateIndexlibService.getList1(time1, time2);
        return SysResult.success(list);
    }

    @GetMapping("/getGrowDateIndexlib2")
    public SysResult getGrowDateIndexlib2(String time1, String time2) {
        List<CropGrowdateIndexlib> list = growdateIndexlibService.getList2(time1, time2);
        return SysResult.success(list);
    }

    @GetMapping("/getGrowDateIndexlib3")
    public SysResult getGrowDateIndexlib3(String date1, String date2, String date3) {
        List<CropGrowdateIndexlib> list3 = growdateIndexlibService.getList3(date1, date2, date3);
        return SysResult.success(list3);
    }

    @GetMapping("/getGrowDateIndexlib4")
    public SysResult getGrowDateIndexlib4(String month) {
        List<CropGrowdateIndexlib> list = growdateIndexlibService.getList4(month);
        return SysResult.success(list);
    }

    @GetMapping("/getGrowDateIndexlib5")
    public SysResult getGrowDateIndexlib5(String month, String cropName) {
        List<CropGrowdateIndexlib> list = growdateIndexlibService.getList5(month, cropName);
        return SysResult.success(list);
    }

    @GetMapping("/getGrowDateIndexlib6")
    public SysResult getGrowDateIndexlib6(String month, String cropName, String type) {
        List<CropGrowdateIndexlib> list = growdateIndexlibService.getList6(month, cropName, type);
        return SysResult.success(list);
    }

    @GetMapping("/getGrowDateIndexlibJoinStation")
    public SysResult getGrowDateIndexlibJoinStation(String indexId) {
        List<String> joinStation = growdateIndexlibService.getJoinStation(indexId);
        return SysResult.success(joinStation);
    }

    @GetMapping("/updateGrowDateIndexlib")
    public SysResult updateGrowDateIndexlib(CropGrowdateIndexlib cropGrowdateIndexlib) {
        Integer rows = growdateIndexlibService.update1(cropGrowdateIndexlib);
        return SysResult.success(rows);
    }

    //产量预报

    @ApiOperation("获取农作物产量预报")
    @GetMapping("/getCropYieldFcst")
    public SysResult getCropYieldFcst(Integer year, String cropName, String type) {
        List<CropyieldFcst> list = cropyieldFcstService.getList(year, cropName, type);
        return SysResult.success(list);
    }
@ApiOperation("产量预报-获取分析统计数据")
@GetMapping("/getHistoryList")
public SysResult getHistoryList(long year1, long year2, String stationId, String type, String cropName){
  //预报
    List<CropYieldFcstListVo> cropYieldFcstListVos = cropyieldFcstService.listByYear(year1, year2, stationId, type, cropName);

    List<CropYieldFcstListVo> listfst = cropYieldFcstListVos.stream().map(
            i -> {
                CropYieldFcstListVo bo = new CropYieldFcstListVo();
                BeanUtils.copyProperties(i, bo);
                double yield = bo.getYield();
                bo.setYield(yield);
                return bo;
            }
    ).collect(Collectors.toList());
    //历史
   List<CropYieldHistoryListVo>  cropYieldHistoryListVos =cropyieldHistoryService.listByYear(year1, year2, stationId, type, cropName);
    List<CropYieldHistoryListVo> listmsg = cropYieldHistoryListVos.stream().map(
            i -> {
                CropYieldHistoryListVo bo = new CropYieldHistoryListVo();
                BeanUtils.copyProperties(i, bo);
                double yield = bo.getYield();
                bo.setYield(yield);
                return bo;
            }
    ).collect(Collectors.toList());
    HashMap<String, Object> map = new HashMap<>();
    map.put("fcst", listfst);
    map.put("msg", listmsg);
    List<Double> list = new ArrayList<>();
    if (listfst.size() >0 || listmsg.size() >0){
        for (int i = 0; i < listmsg.size(); i++) {
            list.add(listmsg.get(i).getYield());
        }
        for (int i = 0; i < listfst.size(); i++) {
            list.add(listfst.get(i).getYield());
        }
    }
    map.put("min", Collections.min(list));
    map.put("max", Collections.max(list));
    return SysResult.success(map);
}

    @GetMapping("/getMsgMediumMaxTemp")
    public SysResult getMsgMediumMaxTemp(String time1, String time2, String stationId) {
        List<String> maxTemp = msgMediumSmallScaleService.getMaxTemp(time1, time2, stationId);
        return SysResult.success(maxTemp);
    }

    @GetMapping("/getMsgMediumMaxTemp1")
    public SysResult getMsgMediumMaxTemp1(String time1, String time2, String stationId) {
        List<String> maxTemp = msgMediumSmallScaleService.getMaxTemp1(time1, time2, stationId);
        return SysResult.success(maxTemp);
    }

    @GetMapping("/getMsgMediumRain")
    public SysResult getMsgMediumRain(String time1, String time2, String stationId) {
        List<String> rain = msgMediumSmallScaleService.getRain(time1, time2, stationId);
        return SysResult.success(rain);
    }

    @GetMapping("/getMsgMediumRain1")
    public SysResult getMsgMediumRain1(String time1, String time2, String stationId) {
        List<String> rain = msgMediumSmallScaleService.getRain1(time1, time2, stationId);
        return SysResult.success(rain);
    }

    @GetMapping("/getMsgMediumRain2")
    public SysResult getMsgMediumRain2(String time1, String time2, String stationId) {
        List<String> rain = msgMediumSmallScaleService.getRain2(time1, time2, stationId);
        return SysResult.success(rain);
    }

    @GetMapping("/getMsgMediumTemp")
    public SysResult getMsgMediumTemp(String time1, String time2, String stationId) {
        List<String> temp = msgMediumSmallScaleService.getTemp(time1, time2, stationId);
        return SysResult.success(temp);
    }

    @GetMapping("/getMsgMediumTemp1")
    public SysResult getMsgMediumTemp1(String time, String stationId) {
        List<String> maxTemp2 = msgMediumSmallScaleService.getMaxTemp2(time, stationId);
        return SysResult.success(maxTemp2);
    }

    @GetMapping("/getMsgMediumWindVelocity")
    public SysResult getMsgMediumWindVelocity(String time1, String time2, String stationId) {
        List<String> windVelocity = msgMediumSmallScaleService.getWindVelocity(time1, time2, stationId);
        return SysResult.success(windVelocity);
    }

    @GetMapping("/getMsgMediumMaxTemp2")
    public SysResult getMsgMediumMaxTemp2(String time, String stationId) {
        List<String> maxTemp2 = msgMediumSmallScaleService.getMaxTemp3(time, stationId);
        return SysResult.success(maxTemp2);
    }

    @GetMapping("/getMsgMediumMinTemp")
    public SysResult getMsgMediumMinTemp(String time1, String time2, String stationId) {
        List<String> minTemp = msgMediumSmallScaleService.getMinTemp(time1, time2, stationId);
        return SysResult.success(minTemp);
    }

    @GetMapping("/getMsgMediumMinTemp1")
    public SysResult getMsgMediumMinTemp1(String time, String stationId) {
        String minTemp1 = msgMediumSmallScaleService.getMinTemp1(time, stationId);
        return SysResult.success(minTemp1);
    }

    @GetMapping("/getMsgMedium")
    public SysResult getMsgMedium(String time, String stationId) {
        List<MsgMediumSmallScale> list7 = msgMediumSmallScaleService.getList7(time, stationId);
        return SysResult.success(list7);
    }

    @GetMapping("/getMsgMediumMaxWind")
    public SysResult getMsgMediumMaxWind(String time, String stationId) {
        List<MsgMediumSmallScale> list7 = msgMediumSmallScaleService.getMaxWind(time, stationId);
        return SysResult.success(list7);
    }

    @GetMapping("/getMsgMediumSumValue")
    public SysResult getMsgMediumSumValue(String stationId, String time) {
        List<MsgMediumSmallScale> sumValue = msgMediumSmallScaleService.getSumValue(stationId, time);
        return SysResult.success(sumValue);
    }

    @GetMapping("/getAgriWeatherDistRecord")
    public SysResult AgriWeatherDistRecord(String stationId, String yield) {
        List<AgriWeatherDistRecord> list = agriWeatherDistRecordService.getList(stationId, yield);
        return SysResult.success(list);
    }


    @GetMapping("/getCropGrowdateFcst1")
    public SysResult getCropGrowdateFcst1(String year, String stationId, String type, String cropName, String growDateName) {
        List<CropGrowdateFcst> list1 = cropGrowdateFcstService.listByParam(year, stationId, type, cropName, growDateName);
        return SysResult.success(list1);
    }

    @ApiOperation("查询发育期预报")
    @GetMapping("/getCropGrowdateFcst2")
    public SysResult getCropGrowdateFcst2(String year, String cropName, String type, String growDateName) {
        List<CropGrowdateFcst> list2 = cropGrowdateFcstService.getList2(year, cropName, type, growDateName);
        return SysResult.success(list2);
    }


    @PostMapping("/updateCropGrowdateFcst")
    public SysResult updateCropGrowdateFcst(CropGrowdateFcst cropGrowdateFcst) {
        Integer rows = cropGrowdateFcstService.update(cropGrowdateFcst);
        return SysResult.success(rows);
    }

    @PostMapping("/saveCropGrowdateFcst")
    public SysResult saveCropGrowdateFcst(CropGrowdateFcst cropGrowdateFcst) {
        Integer rows = cropGrowdateFcstService.save(cropGrowdateFcst);
        return SysResult.success(rows);
    }

    @GetMapping("/getCropGrowForecastDate")
    public SysResult getCropGrowForecastDate(String year, String stationId, String type, String cropName, String growDateName) {
        List<String> forecastDate = cropGrowdateFcstService.getForecastDate(year, stationId, type, cropName, growDateName);
        return SysResult.success(forecastDate);
    }

    @GetMapping("/getCropGrowForecastDate1")
    public SysResult getCropGrowForecastDate1(String year, String stationId, String type, String cropName) {
        List<String> forecastDate = cropGrowdateFcstService.getForecastDate1(year, stationId, type, cropName);
        return SysResult.success(forecastDate);
    }

    @GetMapping("/getCropGrowForecastDate2")
    public SysResult getCropGrowForecastDate2(String year, String stationId, String type, String growDateName) {
        List<String> forecastDate = cropGrowdateFcstService.getForecastDate2(year, stationId, type, growDateName);
        return SysResult.success(forecastDate);
    }

    @GetMapping("/getSrvProductTemplate")
    public SysResult getSrvProductTemplate(String templateType) {
        List<SrvProductTemplate> list = srvProductTemplateService.getList(templateType);
        return SysResult.success(list);
    }

    @GetMapping("/getSrvProductTemplate1")
    public SysResult getSrvProductTemplate1(String templateType, String templateName) {
        List<SrvProductTemplate> list = srvProductTemplateService.getList1(templateType, templateName);
        return SysResult.success(list);
    }

    @PostMapping("/saveSrvProductTemplate")
    public SysResult saveSrvProductTemplate(SrvProductTemplate srvProductTemplate) {
        Integer rows = srvProductTemplateService.save(srvProductTemplate);
        return SysResult.success(rows);
    }

    @GetMapping("/deleteSrvProductTemplate1")
    public SysResult deleteSrvProductTemplate1(String templateType, String templateName) {
        Integer rows = srvProductTemplateService.delete(templateType, templateName);
        return SysResult.success(rows);
    }

    @PostMapping("/updateSrvProductTemplate")
    public SysResult updateSrvProductTemplate(SrvProductTemplate srvProductTemplate) {
        Integer rows = srvProductTemplateService.update(srvProductTemplate);
        return SysResult.success(rows);
    }

    @GetMapping("/getForecastInfoTimeChar")
    public SysResult getForecastInfoTimeChar(String dateChar, String stationId) {
        List<String> timeChar = forecastInfoService.getTimeChar(dateChar, stationId);
        return SysResult.success(timeChar);
    }

    @GetMapping("/getForecastInfo")
    public SysResult getForecastInfo(String dateChar, String timeChar, Integer nTimes, String stationId) {
        List<ForecastInfo> forecastInfo = forecastInfoService.getForecastInfo(dateChar, timeChar, nTimes, stationId);
        return SysResult.success(forecastInfo);
    }

    @GetMapping("/getForecastInfoRain")
    public SysResult getForecastRain(String time1, String time2, String stationId) {
        List<String> rain = forecastInfoService.getRain(time1, time2, stationId);
        return SysResult.success(rain);
    }

    @GetMapping("/getForecastInfoTemp")
    public SysResult getForecastTemp(String time1, String time2, String stationId) {
        List<String> temp = forecastInfoService.getTemp(time1, time2, stationId);
        return SysResult.success(temp);
    }

    @GetMapping("/getForecastInfoMaxTemp")
    public SysResult getForecastMaxTemp(String time, String stationId) {
        List<String> maxTemp = forecastInfoService.getMaxTemp(time, stationId);
        return SysResult.success(maxTemp);
    }

    @GetMapping("/getForecastInfoWindVelocity")
    public SysResult getForecastWindVelocity(String time1, String time2, String stationId) {
        List<String> windVelocity = forecastInfoService.getWindVelocity(time1, time2, stationId);
        return SysResult.success(windVelocity);
    }

    @GetMapping("/getForecastInfoMaxTemp1")
    public SysResult getForecastMaxTemp1(String time, String stationId) {
        List<String> maxTemp1 = forecastInfoService.getMaxTemp1(time, stationId);
        return SysResult.success(maxTemp1);
    }

    @GetMapping("/getForecastInfoMinTemp")
    public SysResult getForecastMinTemp1(String time1, String time2, String stationId) {
        List<String> minTemp = forecastInfoService.getMinTemp(time1, time2, stationId);
        return SysResult.success(minTemp);
    }

    @GetMapping("/getForecastInfoMinTemp1")
    public SysResult getForecastMinTemp2(String time, String stationId) {
        String minTemp = forecastInfoService.getMinTemp1(time, stationId);
        return SysResult.success(minTemp);
    }

    @GetMapping("/getForecastInfo1")
    public SysResult getForecastInfo1(String time, String stationId) {
        List<ForecastInfo> list1 = forecastInfoService.getList1(time, stationId);
        return SysResult.success(list1);
    }

    @GetMapping("/getForecastInfoMaxWind")
    public SysResult getForecastInfoMaxWind(String time, String stationId) {
        List<ForecastInfo> maxWind = forecastInfoService.getMaxWind(time, stationId);
        return SysResult.success(maxWind);
    }

    @GetMapping("/getForecastInfoSumValue")
    public SysResult getForecastInfoSumValue(String stationId, String time) {
        List<ForecastInfo> sumValue = forecastInfoService.getSumValue(stationId, time);
        return SysResult.success(sumValue);
    }

    @GetMapping("/getSpecialSrvStation")
    public SysResult getSpecialSrvStation(String city) {
        List<SpecialSrvStation> list = specialSrvStationService.getList3(city);
        return SysResult.success(list);
    }

    @GetMapping("/getSpecialSrvStation1")
    public SysResult getSpecialSrvStation1(String stationId) {
        List<SpecialSrvStation> list = specialSrvStationService.getList4(stationId);
        return SysResult.success(list);
    }

    @GetMapping("/getSysConfigParamValue")
    public SysResult getSysConfigParamValue(String paramName) {
        List<String> templates = sysConfigService.getTemplates(paramName);
        return SysResult.success(templates);
    }

    @GetMapping("/getCropWeatherDistIndexlib")
    public SysResult getCropWeatherDistIndexlib(String startTime, String endTime) {
        List<CropWeatherDistIndexlib> list = cropWeatherDistIndexlibService.getList(startTime, endTime);
        return SysResult.success(list);
    }

    @GetMapping("/getCropWeatherDistIndexlib1")
    public SysResult getCropWeatherDistIndexlib1(String cropName, String easyHappenType) {
        List<CropWeatherDistIndexlib> list = cropWeatherDistIndexlibService.getList1(cropName, easyHappenType);
        return SysResult.success(list);
    }

//    @GetMapping("/getThirtyYearDayAvgRain")
//    public SysResult getThirtyYearDayAvgRain(String time1,String time2,String stationId){
//        String avgRain = thirtyYearDayStaticsService.getAvgRain(time1, time2, stationId);
//        return SysResult.success(avgRain);
//    }

    @GetMapping("/getThirtyYearDayAvgTemp")
    public SysResult getThirtyYearDayAvgTemp(String time1, String time2, String stationId) {
        String avgTemp1 = thirtyYearDayStaticsService.getAvgTemp1(time1, time2, stationId);
        return SysResult.success(avgTemp1);
    }

    @GetMapping("/getThirtyYearDayAvgWindVelocity")
    public SysResult getThirtyYearDayAvgWindVelocity(String time1, String time2, String stationId) {
        String avgWindVelocity = thirtyYearDayStaticsService.getAvgWindVelocity(time1, time2, stationId);
        return SysResult.success(avgWindVelocity);
    }

    @GetMapping("/getThirtyYearDayMaxTemp")
    public SysResult getThirtyYearDayMaxTemp(String time1, String time2, String stationId) {
        String maxTemp1 = thirtyYearDayStaticsService.getMaxTemp1(time1, time2, stationId);
        return SysResult.success(maxTemp1);
    }

    @GetMapping("/getThirtyYearDayMinTemp")
    public SysResult getThirtyYearDayMinTemp(String time1, String time2, String stationId) {
        String minTemp1 = thirtyYearDayStaticsService.getMinTemp1(time1, time2, stationId);
        return SysResult.success(minTemp1);
    }

    @GetMapping("/getThirtyYearDayAvgRain1")
    public SysResult getThirtyYearDayAvgRain1(String time1, String time2, String stationId) {
        String avgRain1 = thirtyYearDayStaticsService.getAvgRain1(time1, time2, stationId);
        return SysResult.success(avgRain1);
    }

    @GetMapping("/getThirtyYearDayAvgRain2")
    public SysResult getThirtyYearDayAvgRain2(String day1, String day2, String stationId) {
        String avgRain1 = thirtyYearDayStaticsService.getAvgRain2(Integer.parseInt(day1), Integer.parseInt(day2), stationId);
        return SysResult.success(avgRain1);
    }

    @GetMapping("/getThirtyYearDayAvgWindV")
    public SysResult getThirtyYearDayAvgWindV(String time1, String time2, String stationId) {
        String avgWindV = thirtyYearDayStaticsService.getAvgWindV(time1, time2, stationId);
        return SysResult.success(avgWindV);
    }


    @GetMapping("/getThirtyYearDaySumHour")
    public SysResult getThirtyYearDaySumHour(String time1, String time2, String stationId) {
        List<String> sumHour = thirtyYearDayStaticsService.getSumHour(time1, time2, stationId);
        return SysResult.success(sumHour);
    }

    @GetMapping("/getThirtyYearDayMaxMinTemp")
    public SysResult getThirtyYearDayMaxMinTemp(String date, String stationId) {
        List<ThirtyYearDayStatics> maxMinTemp = thirtyYearDayStaticsService.getMaxMinTemp(date, stationId);
        return SysResult.success(maxMinTemp);
    }

    @GetMapping("getThirtyYearDayRain")
    public SysResult getThirtyYearDayRain(String date, String stationId) {
        List<String> rain1 = thirtyYearDayStaticsService.getRain1(date, stationId);
        return SysResult.success(rain1);
    }

    @GetMapping("/getThirtyYearDayMaxRain")
    public SysResult getThirtyYearDayMaxRain(String day1, String day2, String stationId) {
        String maxRain = thirtyYearDayStaticsService.getMaxRain(Integer.parseInt(day1), Integer.parseInt(day2), stationId);
        return SysResult.success(maxRain);
    }

    @GetMapping("/getThirtyYearDayMaxRain1")
    public SysResult getThirtyYearDayMaxRain1(String day1, String day2, String stationId) {
        String maxRain = thirtyYearDayStaticsService.getMaxRain1(Integer.parseInt(day1), Integer.parseInt(day2), stationId);
        return SysResult.success(maxRain);
    }

    @GetMapping("/getThirtyYearDay")
    public SysResult getThirtyYearDay(String day1, String day2, String stationId) {
        List<ThirtyYearDayStatics> list = thirtyYearDayStaticsService.getList(Integer.parseInt(day1), Integer.parseInt(day2), stationId);
        return SysResult.success(list);
    }

    @GetMapping("/getThirtyYearDay1")
    public SysResult getThirtyYearDay1(String day1, String day2, String stationId) {
        List<ThirtyYearDayStatics> list = thirtyYearDayStaticsService.getList1(Integer.parseInt(day1), Integer.parseInt(day2), stationId);
        return SysResult.success(list);
    }

    @GetMapping("/getDiseaseIndexlib")
    public SysResult getDiseaseIndexlib(String startTime, String endTime) {
        List<Diseaseindexlib> list = diseaseindexlibService.getList(startTime, endTime);
        return SysResult.success(list);
    }

    @GetMapping("/deleteAgriProduct")
    public SysResult deleteAgriProduct(String id) {
        Integer rows = agriProductService.deleteById(id);
        return SysResult.success(rows);
    }


    @PostMapping("/saveAgriProduct")
    public SysResult saveAgriProduct(AgriProduct agriProduct) {
       AgriProduct agriProduct1= agriProductService.saveProduct(agriProduct);
        return SysResult.success(agriProduct1);
    }

    @PostMapping("/updateAgriProduct")
    public SysResult updateAgriProduc(AgriProduct agriProduct) {
        Integer rows = agriProductService.update(agriProduct);
        return SysResult.success(rows);
    }

    @GetMapping("/getBadCondition")
    public SysResult getBadCondition(String indexId, String climateCondition, String contrastType1, String contrastType2, String climateConditionType, String climateConditionValue) {
        List<BadCondition> list = badConditionService.getList(indexId, climateCondition, contrastType1, contrastType2, climateConditionType,  climateConditionValue);
        return SysResult.success(list);
    }

    //日农事预报


    @GetMapping("/getTownshipForecastTemp")
    public SysResult getTownshipForecastTemp(String dateChar, String timeChar, String nTimes, String temp, String stationId) {
        List<String> list = townshipForecastService.getTemp(dateChar, timeChar, nTimes, temp, stationId);
        return SysResult.success(list);
    }

    @GetMapping("/getTownshipForecastWindS")
    public SysResult getTownshipForecastWindS(String dateChar, String timeChar, String nTimes, String winds, String stationId) {
        List<String> list = townshipForecastService.getWindS(dateChar, timeChar, nTimes, winds, stationId);
        return SysResult.success(list);
    }

    @GetMapping("/getTownshipForecastPress")
    public SysResult getTownshipForecastPress(String dateChar, String timeChar, String nTimes, String press, String stationId) {
        List<String> list = townshipForecastService.getPress(dateChar, timeChar, nTimes, press, stationId);
        return SysResult.success(list);
    }

    @GetMapping("/getTownshipForecastHumid")
    public SysResult getTownshipForecastHumid(String dateChar, String timeChar, String nTimes, String humid, String stationId) {
        List<String> list = townshipForecastService.getHumid(dateChar, timeChar, nTimes, humid, stationId);
        return SysResult.success(list);
    }

    @GetMapping("/getTownShipStation")
    public SysResult getTownShipStation(String city) {
        List<TownshipStation> list = townshipStationService.getList1(city);
        return SysResult.success(list);
    }

//<----------------------------------------------------------------------------------------------------------------------------------------->


    @ApiOperation("农用天气预报--产品生成")
    @GetMapping("/agriculturalWeatherForecast")
    public String agriculturalWeatherForecast(
            String phase, String admin, String title, String tendencies,
            String advice, String tel, HttpServletResponse response) throws IOException {
        String result = agriProductService.agriculturalWeatherForecast(phase, admin, title, tendencies, advice, tel, response);
        if (result.equals("")){
            return ("产品生成失败！！！");
        }else if (result.equals("成功")){
            return ("文档查询成功！");
        }
        return (result);
    }

    @ApiOperation("发育期预报--产品生成")
    @GetMapping("/developmentalForecasting")
    public String developmentalForecasting(String cropName, String stationName, String growdateName, String type, String dateTime, String date, String d, String d1, String a, String b, String t, HttpServletResponse response) throws IOException {
        String result = agriProductService.developmentalForecasting(cropName, stationName, growdateName, type, dateTime, date, d, d1, a, b, t, response);
        if (result.equals("")){
            return ("产品生成失败！！！");
        }else if (result.equals("成功")){
            return ("文档查询成功！");
        }
        return (result);
    }

}
